<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="病患姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="联系方式" prop="doctorTel">
        <el-input
          v-model="queryParams.doctorTel"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="doctorAdd">
        <el-input
          v-model="queryParams.doctorAdd"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入时间" prop="registrationStarttime">
        <el-date-picker clearable
                        v-model="queryParams.registrationStarttime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择录入时间"
        >
        </el-date-picker>
      </el-form-item>



      <el-form-item label="医师" prop="doctorId">

        <el-select
          v-model="doctorId"
          placeholder="请选择医师"
          @change="doctorChange(doctorId)"
        >
          <el-option
            v-for="item in doctorLists"
            :label="item.doctorName"
            :value="item.doctorId"
          >
          </el-option>
        </el-select>
      </el-form-item>


      <el-form-item label="科室" prop="deptId">

        <el-select
          v-model="departmentid"
          placeholder="请选择科室"
          @change="deptLikeChange(departmentid)"
        >
          <el-option
            v-for="item in departmentlist"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>

      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="registrationList" @selection-change="handleSelectionChange">
      <el-table-column label="科室名称" align="center" prop="deptName"/>
      <el-table-column label="排队号" align="center" prop="sortNum"/>
      <el-table-column label="病患姓名" align="center" prop="patientName"/>
      <el-table-column label="联系方式" align="center" prop="doctorTel"/>
      <el-table-column label="地址" align="center" prop="doctorAdd"/>
      <el-table-column label="挂号时间" align="center" prop="registrationStarttime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.registrationStarttime, '{y}-{m}-{d}: {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="医师姓名" align="center" prop="doctorName"/>

      <el-table-column label="状态" align="center" prop="state"/>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getLists"
    />


  </div>

</template>

<script>
import {
  getRegistration,
  delRegistration,
  addRegistration,
  updateRegistration,
  getdeptList,
  getDoctorList,
  okPayListRegistrations,
  getDoctorLikeList
} from '@/api/outpatient/registrationSort'
import item from '@/layout/components/Sidebar/Item.vue'

export default {
  name: 'Registration',
  data() {
    return {
      doctorId:'',
      doctorLists:[],


      value:'',
      PatientStatus:[
        {
          value:'未缴费',
          label:'未缴费'
        },
        {
          value:'已缴费',
          label:'已缴费'
        },
        {
          value:'已就诊',
          label:'已就诊'
        }
      ],

      //部门
      departmentlist: [],
      departmentid: null,
      //人员
      personlist: [],
      personid: null,


      //禁用
      disabled: true,

      deptDoct: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 挂号流水表表格数据
      registrationList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientName: null,
        dickerSex: null,
        patientIdcard: null,
        patientAge: null,
        doctorTel: null,
        doctorAdd: null,
        registrationStarttime: null,
        registrationEndtime: null,
        registrationMoney: null,
        doctorId: null,
        deptId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {

    this.getdepartmentlist()
    // this.getList()
    this.getLists()

    this.getDoctorLists()

  },
  methods: {
    deptLikeChange(id){
      this.queryParams.deptId = id
    },
    getDoctorLists(){
      getDoctorLikeList().then(response => {
        this.doctorLists = response.data
        this.loading = false
      })
    },
    doctorChange(doctorId){
      this.queryParams.doctorId = doctorId
    },
    sss(ss){
      this.form.state = ss
    },
    doctorWork(id){
      this.form.doctorId = id
    },

    getdepartmentlist() {
      getdeptList().then(response => {
        this.departmentlist = response.data.data
        this.loading = false
      })
    },
    changeset() {
      this.form.deptId = this.departmentid
      getDoctorList().then(response => {
        let data = response.data.data
        this.loading = false
        //如果部门id不为空
        if (this.departmentid) {
          //切换的时候人员清空，防止bug
          this.personlist = []
          //禁用取消
          this.disabled = false

          data.forEach(item => {

            if (item.departmentid == this.departmentid) {
              this.personlist.push(item)
            }
          })
        } else {
          //选中的部门为空，则清空人员列表
          this.personlist = []
          this.disabled = true

        }
      })
    },

    /** 查询挂号流水表列表 */
    getLists() {
      this.loading = true
      okPayListRegistrations(this.queryParams).then(response => {
        this.registrationList = response.rows
        console.log(this.registrationList)
        this.total = response.total
        this.loading = false
      })
    },

    cancel() {
      this.open = false
      this.reset()
      this.departmentid = null
      this.personid = null
    },
    // 表单重置
    reset() {
      this.form = {
        registrationId: null,
        patientName: null,
        dickerSex: null,
        patientIdcard: null,
        patientAge: null,
        doctorTel: null,
        doctorAdd: null,
        registrationStarttime: null,
        registrationEndtime: null,
        registrationMoney: null,
        doctorId: null,
        deptId: null,
        state:null



      }
      this.resetForm('form')
      this.value = []
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.doctorId=''
      this.departmentid=''
      this.getLists()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
  }
}
</script>
